package com.utilus;



import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandler;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import org.springframework.stereotype.Component;


@Component
@ChannelHandler.Sharable
public class ClientChannelHandler extends SimpleChannelInboundHandler<Object> {


    @Override
    protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
        System.out.println("tcp服务器回复 : " + msg);
    }



    @Override
    public void channelActive(ChannelHandlerContext ctx) throws Exception {

        byte[] setHex= new byte[22];
        setHex[0]=0x55;
        setHex[1]=0x55;
        setHex[2]=0x01;
        setHex[3]=0x00;
        setHex[4]=0x01;
        setHex[5]=0x01;
        setHex[6]=0x02;
        setHex[7]=0x03;
        setHex[8]=0x01;
        setHex[9]=0x02;
        setHex[10]=0x03;
        setHex[11]=0x04;
        setHex[12]=0x05;
        setHex[13]=0x06;
        setHex[14]=0x00;
        setHex[15]=0x02;
        setHex[16]='{';
        setHex[17]='}';
        setHex[18]=0x01;
        setHex[19]=0x17;
        setHex[20]=0x13;
        setHex[21]=0x14;


        ByteBuf encoded = ctx.channel().alloc().buffer(4 * (setHex.length-4));
        encoded.writeBytes(setHex);
        ctx.channel().writeAndFlush(encoded).syncUninterruptibly();

    }

}
